home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue55 / ccorn / Srv_TLB.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2000-02-06  |  9.2 KB  |  269 lines

  1. unit Srv_TLB;
  2.  
  3. // ************************************************************************ //
  4. // WARNING                                                                    
  5. // -------                                                                    
  6. // The types declared in this file were generated from data read from a       
  7. // Type Library. If this type library is explicitly or indirectly (via        
  8. // another type library referring to this type library) re-imported, or the   
  9. // 'Refresh' command of the Type Library Editor activated while editing the   
  10. // Type Library, the contents of this file will be regenerated and all        
  11. // manual modifications will be lost.                                         
  12. // ************************************************************************ //
  13.  
  14. // PASTLWTR : $Revision:   1.88  $
  15. // File generated on 2/6/2000 6:36:41 AM from Type Library described below.
  16.  
  17. // *************************************************************************//
  18. // NOTE:                                                                      
  19. // Items guarded by $IFDEF_LIVE_SERVER_AT_DESIGN_TIME are used by properties  
  20. // which return objects that may need to be explicitly created via a function 
  21. // call prior to any access via the property. These items have been disabled  
  22. // in order to prevent accidental use from within the object inspector. You   
  23. // may enable them by defining LIVE_SERVER_AT_DESIGN_TIME or by selectively   
  24. // removing them from the $IFDEF blocks. However, such items must still be    
  25. // programmatically created via a method of the appropriate CoClass before    
  26. // they can be used.                                                          
  27. // ************************************************************************ //
  28. // Type Lib: C:\My Documents\DelphiMag\April00\Q_Comp\Srv.tlb (1)
  29. // IID\LCID: {B43DD7DB-21F8-4244-A494-C4793366691B}\0
  30. // Helpfile: 
  31. // DepndLst: 
  32. //   (1) v2.0 stdole, (C:\WINNT\System32\stdole2.tlb)
  33. //   (2) v4.0 StdVCL, (C:\WINNT\System32\STDVCL40.DLL)
  34. // ************************************************************************ //
  35. {$TYPEDADDRESS OFF} // Unit must be compiled without type-checked pointers. 
  36. interface
  37.  
  38. uses Windows, ActiveX, Classes, Graphics, OleServer, OleCtrls, StdVCL;
  39.  
  40. // *********************************************************************//
  41. // GUIDS declared in the TypeLibrary. Following prefixes are used:        
  42. //   Type Libraries     : LIBID_xxxx                                      
  43. //   CoClasses          : CLASS_xxxx                                      
  44. //   DISPInterfaces     : DIID_xxxx                                       
  45. //   Non-DISP interfaces: IID_xxxx                                        
  46. // *********************************************************************//
  47. const
  48.   // TypeLibrary Major and minor versions
  49.   SrvMajorVersion = 1;
  50.   SrvMinorVersion = 0;
  51.  
  52.   LIBID_Srv: TGUID = '{B43DD7DB-21F8-4244-A494-C4793366691B}';
  53.  
  54.   IID_IQTest: TGUID = '{C16B6A4C-842C-417F-8BF2-2F306F6C6B59}';
  55.   CLASS_QTest: TGUID = '{64C576F0-C9A7-420A-9EAB-0BE98264BC9D}';
  56. type
  57.  
  58. // *********************************************************************//
  59. // Forward declaration of types defined in TypeLibrary                    
  60. // *********************************************************************//
  61.   IQTest = interface;
  62.   IQTestDisp = dispinterface;
  63.  
  64. // *********************************************************************//
  65. // Declaration of CoClasses defined in Type Library                       
  66. // (NOTE: Here we map each CoClass to its Default Interface)              
  67. // *********************************************************************//
  68.   QTest = IQTest;
  69.  
  70.  
  71. // *********************************************************************//
  72. // Interface: IQTest
  73. // Flags:     (4416) Dual OleAutomation Dispatchable
  74. // GUID:      {C16B6A4C-842C-417F-8BF2-2F306F6C6B59}
  75. // *********************************************************************//
  76.   IQTest = interface(IDispatch)
  77.     ['{C16B6A4C-842C-417F-8BF2-2F306F6C6B59}']
  78.     procedure SendText(const Value: WideString; Time: TDateTime); safecall;
  79.   end;
  80.  
  81. // *********************************************************************//
  82. // DispIntf:  IQTestDisp
  83. // Flags:     (4416) Dual OleAutomation Dispatchable
  84. // GUID:      {C16B6A4C-842C-417F-8BF2-2F306F6C6B59}
  85. // *********************************************************************//
  86.   IQTestDisp = dispinterface
  87.     ['{C16B6A4C-842C-417F-8BF2-2F306F6C6B59}']
  88.     procedure SendText(const Value: WideString; Time: TDateTime); dispid 1;
  89.   end;
  90.  
  91. // *********************************************************************//
  92. // The Class CoQTest provides a Create and CreateRemote method to          
  93. // create instances of the default interface IQTest exposed by              
  94. // the CoClass QTest. The functions are intended to be used by             
  95. // clients wishing to automate the CoClass objects exposed by the         
  96. // server of this typelibrary.                                            
  97. // *********************************************************************//
  98.   CoQTest = class
  99.     class function Create: IQTest;
  100.     class function CreateRemote(const MachineName: string): IQTest;
  101.   end;
  102.  
  103.  
  104. // *********************************************************************//
  105. // OLE Server Proxy class declaration
  106. // Server Object    : TQTest
  107. // Help String      : Queued Test Object
  108. // Default Interface: IQTest
  109. // Def. Intf. DISP? : No
  110. // Event   Interface: 
  111. // TypeFlags        : (2) CanCreate
  112. // *********************************************************************//
  113. {$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
  114.   TQTestProperties= class;
  115. {$ENDIF}
  116.   TQTest = class(TOleServer)
  117.   private
  118.     FIntf:        IQTest;
  119. {$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
  120.     FProps:       TQTestProperties;
  121.     function      GetServerProperties: TQTestProperties;
  122. {$ENDIF}
  123.     function      GetDefaultInterface: IQTest;
  124.   protected
  125.     procedure InitServerData; override;
  126.   public
  127.     constructor Create(AOwner: TComponent); override;
  128.     destructor  Destroy; override;
  129.     procedure Connect; override;
  130.     procedure ConnectTo(svrIntf: IQTest);
  131.     procedure Disconnect; override;
  132.     procedure SendText(const Value: WideString; Time: TDateTime);
  133.     property  DefaultInterface: IQTest read GetDefaultInterface;
  134.   published
  135. {$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
  136.     property Server: TQTestProperties read GetServerProperties;
  137. {$ENDIF}
  138.   end;
  139.  
  140. {$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
  141. // *********************************************************************//
  142. // OLE Server Properties Proxy Class
  143. // Server Object    : TQTest
  144. // (This object is used by the IDE's Property Inspector to allow editing
  145. //  of the properties of this server)
  146. // *********************************************************************//
  147.  TQTestProperties = class(TPersistent)
  148.   private
  149.     FServer:    TQTest;
  150.     function    GetDefaultInterface: IQTest;
  151.     constructor Create(AServer: TQTest);
  152.   protected
  153.   public
  154.     property DefaultInterface: IQTest read GetDefaultInterface;
  155.   published
  156.   end;
  157. {$ENDIF}
  158.  
  159.  
  160. procedure Register;
  161.  
  162. implementation
  163.  
  164. uses ComObj;
  165.  
  166. class function CoQTest.Create: IQTest;
  167. begin
  168.   Result := CreateComObject(CLASS_QTest) as IQTest;
  169. end;
  170.  
  171. class function CoQTest.CreateRemote(const MachineName: string): IQTest;
  172. begin
  173.   Result := CreateRemoteComObject(MachineName, CLASS_QTest) as IQTest;
  174. end;
  175.  
  176. procedure TQTest.InitServerData;
  177. const
  178.   CServerData: TServerData = (
  179.     ClassID:   '{64C576F0-C9A7-420A-9EAB-0BE98264BC9D}';
  180.     IntfIID:   '{C16B6A4C-842C-417F-8BF2-2F306F6C6B59}';
  181.     EventIID:  '';
  182.     LicenseKey: nil;
  183.     Version: 500);
  184. begin
  185.   ServerData := @CServerData;
  186. end;
  187.  
  188. procedure TQTest.Connect;
  189. var
  190.   punk: IUnknown;
  191. begin
  192.   if FIntf = nil then
  193.   begin
  194.     punk := GetServer;
  195.     Fintf:= punk as IQTest;
  196.   end;
  197. end;
  198.  
  199. procedure TQTest.ConnectTo(svrIntf: IQTest);
  200. begin
  201.   Disconnect;
  202.   FIntf := svrIntf;
  203. end;
  204.  
  205. procedure TQTest.DisConnect;
  206. begin
  207.   if Fintf <> nil then
  208.   begin
  209.     FIntf := nil;
  210.   end;
  211. end;
  212.  
  213. function TQTest.GetDefaultInterface: IQTest;
  214. begin
  215.   if FIntf = nil then
  216.     Connect;
  217.   Assert(FIntf <> nil, 'DefaultInterface is NULL. Component is not connected to Server. You must call ''Connect'' or ''ConnectTo'' before this operation');
  218.   Result := FIntf;
  219. end;
  220.  
  221. constructor TQTest.Create(AOwner: TComponent);
  222. begin
  223.   inherited Create(AOwner);
  224. {$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
  225.   FProps := TQTestProperties.Create(Self);
  226. {$ENDIF}
  227. end;
  228.  
  229. destructor TQTest.Destroy;
  230. begin
  231. {$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
  232.   FProps.Free;
  233. {$ENDIF}
  234.   inherited Destroy;
  235. end;
  236.  
  237. {$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
  238. function TQTest.GetServerProperties: TQTestProperties;
  239. begin
  240.   Result := FProps;
  241. end;
  242. {$ENDIF}
  243.  
  244. procedure TQTest.SendText(const Value: WideString; Time: TDateTime);
  245. begin
  246.   DefaultInterface.SendText(Value, Time);
  247. end;
  248.  
  249. {$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
  250. constructor TQTestProperties.Create(AServer: TQTest);
  251. begin
  252.   inherited Create;
  253.   FServer := AServer;
  254. end;
  255.  
  256. function TQTestProperties.GetDefaultInterface: IQTest;
  257. begin
  258.   Result := FServer.DefaultInterface;
  259. end;
  260.  
  261. {$ENDIF}
  262.  
  263. procedure Register;
  264. begin
  265.   RegisterComponents('Servers',[TQTest]);
  266. end;
  267.  
  268. end.
  269.